home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Apple Developer Connection Student Program
/
ADC Tools Sampler CD Disk 3 1999.iso
/
Cool Demos, SDKs, & Tools
/
Demos⁄Tools⁄Offers
/
Eiffel for CW beta 3
/
EiffelS2
/
LIBRARY
/
MOTEL
/
Files.c
< prev
next >
Wrap
Text File
|
1999-05-26
|
8KB
|
325 lines
/*------------------------------------------------------------------*/
/* Eiffel/S II MacOS Runtime */
/*------------------------------------------------------------------*/
/* Author : Ian Joyner */
/* Release : 1.0 */
/* Date : Dec. 1997 */
/* Copyright : Ian Joyner */
/*------------------------------------------------------------------*/
#include <Files.h>
#include <StandardFile.h>
#include <Eiffel2.h>
#include "MOTEL.h"
/********************************************************************/
/* */
/* FILES and DIRECTORIES */
/* */
/********************************************************************/
INTEGER platform_file_rename (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name, ConstStr255Param new_name)
{
Str255 scratch;
strcpy (scratch, name);
c2pstr ((char *)scratch);
strcpy (scratch_string, new_name);
c2pstr ((char *)scratch_string);
return HRename (vol_id, dir_id, scratch, scratch_string);
}
INTEGER platform_file_move (INTEGER vol_id, INTEGER dir_id, INTEGER to_dir_id, ConstStr255Param name)
{
Str255 scratch;
strcpy (scratch, name);
c2pstr ((char *)scratch);
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return CatMove (vol_id, dir_id, scratch, to_dir_id, scratch_string);
}
INTEGER platform_file_delete (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return HDelete (vol_id, dir_id, scratch_string);
}
/********************************************************************/
/* */
/* VOLUMES */
/* */
/********************************************************************/
INTEGER platform_file_volume_eject (INTEGER vol_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return Eject (scratch_string, vol_id);
}
INTEGER platform_file_volume_unmount (INTEGER vol_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return UnmountVol (scratch_string, vol_id);
}
INTEGER platform_file_volume_flush (INTEGER vol_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return FlushVol (scratch_string, vol_id);
}
INTEGER platform_file_volume_set_default (INTEGER vol_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return SetVol (scratch_string, vol_id);
}
INTEGER platform_file_volume_get_default (INTEGER *vol_id)
{
OSErr e;
int v;
long d;
e = HGetVol (&scratch_string, &v, &d);
*vol_id = v;
return e;
}
/********************************************************************/
/* */
/* DIRECTORIES */
/* */
/********************************************************************/
INTEGER platform_file_directory_create (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name, POINTER id)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return DirCreate (vol_id, dir_id, scratch_string, (INTEGER *)id);
}
INTEGER platform_file_directory_set_default (INTEGER vol_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return SetVol (scratch_string, vol_id);
}
INTEGER platform_file_directory_get_default (INTEGER *dir_id)
{
OSErr e;
int v;
long d;
e = HGetVol (&scratch_string, &v, &d);
*dir_id = d;
return e;
}
/********************************************************************/
/* */
/* FILES */
/* */
/********************************************************************/
INTEGER platform_file_create (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name, ConstStr255Param c, ConstStr255Param ft)
{
OSType creator;
OSType file_type;
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
strncpy (&creator, c, 4);
strncpy (&file_type, ft, 4);
return HCreate (vol_id, dir_id, scratch_string, creator, file_type);
}
INTEGER platform_file_open (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name, INTEGER permission, INTEGER *id)
{
short ref_num;
INTEGER result;
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
result = HOpen (vol_id, dir_id, scratch_string, permission, &ref_num);
*id = ref_num;
return result;
}
INTEGER platform_file_openDF (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name, INTEGER permission, INTEGER *id)
{
short ref_num;
INTEGER result;
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
result = HOpenDF (vol_id, dir_id, scratch_string, permission, &ref_num);
*id = ref_num;
return result;
}
INTEGER platform_file_openRF (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name, INTEGER permission, INTEGER *id)
{
short ref_num;
INTEGER result;
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
result = HOpenRF (vol_id, dir_id, scratch_string, permission, &ref_num);
*id = ref_num;
return result;
}
INTEGER platform_file_read (INTEGER id, INTEGER *count, POINTER buffer)
{
return FSRead (id, count, buffer);
}
INTEGER platform_file_write (INTEGER id, INTEGER *count, POINTER buffer)
{
return FSWrite (id, count, buffer);
}
INTEGER platform_file_close (INTEGER id)
{
return FSClose (id);
}
INTEGER platform_file_position (INTEGER id, INTEGER *pos)
{
return GetFPos (id, pos);
}
INTEGER platform_file_set_position (INTEGER id, INTEGER mode, INTEGER pos)
{
return SetFPos (id, mode, pos);
}
INTEGER platform_file_eof (INTEGER id, INTEGER *pos)
{
return GetEOF (id, pos);
}
INTEGER platform_file_set_eof (INTEGER id, INTEGER new_eof)
{
return SetEOF (id, new_eof);
}
INTEGER platform_file_allocate (INTEGER id, INTEGER *count)
{
return Allocate (id, count);
}
INTEGER platform_file_allocate_contiguous (INTEGER id, INTEGER *count)
{
return AllocContig (id, count);
}
INTEGER platform_file_acquire (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return HSetFLock (vol_id, dir_id, scratch_string);
}
INTEGER platform_file_release (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name)
{
strcpy (scratch_string, name);
c2pstr ((char *)scratch_string);
return HRstFLock (vol_id, dir_id, scratch_string);
}
INTEGER platform_file_exchange (INTEGER vol_id, INTEGER dir_id, ConstStr255Param name,
INTEGER other_vol_id, INTEGER other_dir_id, ConstStr255Param other_name)
{
FSSpec fs, other_fs;
Str255 scratch;
strcpy (scratch, name);
c2pstr ((char *)scratch);
strcpy (scratch_string, other_name);
c2pstr ((char *)scratch_string);
FSMakeFSSpec (vol_id, dir_id, scratch, &fs);
FSMakeFSSpec (other_vol_id, other_dir_id, scratch_string, &other_fs);
return FSpExchangeFiles (&fs, &other_fs);
}
/********************************************************************/
/* */
/* STANDARD FILE DIALOGS */
/* */
/********************************************************************/
OSType type_list [20];
int n_types;
StandardFileReply sfr;
POINTER platform_file_get_file (BOOLEAN use_filter, BOOLEAN *good, INTEGER *type, INTEGER *vol_id, INTEGER *dir_id)
{
StandardGetFile (0, n_types, type_list, &sfr);
*good = sfr.sfGood;
*type = sfr.sfType;
*vol_id = sfr.sfFile.vRefNum;
*dir_id = sfr.sfFile.parID;
n_types = 0;
p2cstr (&sfr.sfFile.name);
return &sfr.sfFile.name;
}
void platform_file_add_type (POINTER t)
{
strncpy (&type_list [n_types], t, 4);
n_types += 1;
}
POINTER platform_file_put_file (POINTER prompt, POINTER initial_file_name, BOOLEAN *good, INTEGER *vol_id, INTEGER *dir_id)
{
Str255 scratch;
strcpy (scratch, prompt);
c2pstr ((char *)scratch);
strcpy (scratch_string, initial_file_name);
c2pstr ((char *)scratch_string);
StandardPutFile (scratch, scratch_string, &sfr);
*good = sfr.sfGood;
*vol_id = sfr.sfFile.vRefNum;
*dir_id = sfr.sfFile.parID;
p2cstr (&sfr.sfFile.name);
return &sfr.sfFile.name;
}